package com.socialnetspace.web;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.appengine.api.NamespaceManager;

public class NamespaceFilter implements javax.servlet.Filter {

	
	private FilterConfig filterConfig;
	
	private Log logger = LogFactory.getLog(this.getClass().getName());
	
	
	@Override
	public void init(FilterConfig arg0) throws ServletException {
		filterConfig = arg0;
	}
	
	
	@Override
	public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
			throws IOException, ServletException {

		logger.info(filterConfig.getFilterName());
		
		if (NamespaceManager.get() == null) {
			NamespaceManager.set(NamespaceManager.getGoogleAppsNamespace());
		}
		chain.doFilter(req, res);
	}

	
	@Override
	public void destroy() {
	
		
	}
	
}